class Storage {
  constructor(storageType = "localStorage") {
    // this.key = import.meta.env.MODE + "_" + key;
    // this.key = key;
    // this.isObject = isObject;
    this.storage = window[storageType]; // 根据参数选择存储类型
  }

  get(key ,isObject = false) {
    let value = this.storage.getItem(key);
    if (isObject) {
      try {
        value = JSON.parse(value);
      } catch {
        value = null;
      }
    }
    return value;
  }

  set(key,value ,isObject = false ) {
    this.storage.setItem(
      key,
      isObject ? JSON.stringify(value) : value
    );
  }

  remove(key) {
    this.storage.removeItem(key);
  }
}

export default new Storage();